package com.hqyj.purchase.controller;
import com.hqyj.purchase.model.PurchaseInfo;
import frame.purchase.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * @author qianyexiuci
 * @date 2021/09/06 17:03
 */
@Controller
@RequestMapping("/purchaseController")
public class AddPurchaseController extends BaseController {

    @RequestMapping("/add.do")
    public String addPurchase(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model){
        int id = Integer.parseInt(request.getParameter("id"));
        PurchaseInfo purchaseInfo= purchaseService.queryPurchaseInfoById(id);

        String tradeName =purchaseInfo.getTradeName();

        String provider = infoGoodsService.queryAllByTradeName(tradeName).getGoodsGys();

        int price = infoGoodsService.queryAllByTradeName(tradeName).getGoodsPrice();

        int rows = purchaseService.updatePurchase(purchaseInfo,provider,price);

        List<PurchaseInfo> purchaseInfoList = purchaseService.queryAllPurchaseInfo();
        model.addAttribute("purchaseInfoList",purchaseInfoList);

    return  "view/purchase/listPurchase";
    }

}
